package com.yuanjin.util;

import com.yuanjin.activity.FriendShowUploadActivity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class AsyncTask_ImageUpload extends AsyncTask<String, Integer, Boolean> {
	private String uploadUrl;
	private String srcPath;
	private Bitmap bitmap;
	private Context context;
	private String numString;

	public AsyncTask_ImageUpload(Context context, String uploadUrl,
			String srcPath, Bitmap bitmap) {
		this.uploadUrl = uploadUrl;
		this.srcPath = srcPath;
		this.bitmap = bitmap;
		this.context = context;
	}

	@Override
	protected Boolean doInBackground(String... params) {
		Boolean result = FileUtils.uploadBitmapFile(uploadUrl, srcPath, bitmap);
		numString=params[0];//图片的有效张数
		return result;
	}

	@Override
	protected void onPostExecute(Boolean result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
		if (result) {
			
			Yuanjin.uploadNum++;
			Log.e("test", "------------------->图片上传成功了"+Yuanjin.uploadNum);
			if ((Yuanjin.uploadNum+"").equals(numString)) {
				//若是最后一张则退出
				((Activity)context).finish();
			}
			Toast.makeText(context, "上传成功"+Yuanjin.uploadNum, Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(context, "上传失败，请重试。。", Toast.LENGTH_SHORT).show();
		}
	}
}
